from src.models.base_model import BaseModel
from src.exts import db

class User(BaseModel):
    """用户模型"""
    __tablename__ = "tb_user"
    
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(128), unique=True, nullable=False)
    password = db.Column(db.String(320), nullable=False)
    avatar = db.Column(db.String(200), nullable=True)
    is_super_user = db.Column(db.Boolean, nullable=True, default=False)     # 超级管理员标识
    is_active = db.Column(db.Boolean, nullable=True, default=True)          # 是否为活跃用户
    is_staff = db.Column(db.Boolean, nullable=True, default=False)          # 是否允许登录后台
    
    
    def to_dict(self):
        model_dict = {
            "username": self.username,
            "password": self.password,
            "avatar": self.avatar,
            "is_super_user": self.is_super_user,
            "is_active": self.is_active,
            "is_staff": self.is_staff
        }
        return model_dict